package org.me.marble;

import android.opengl.GLU;
import javax.microedition.khronos.opengles.GL10;

/**
*
* @author tungi
*/

public class Camera{
    private Vector point;
    private float i=0;

    public Camera(){
        point=new Vector();
    }

    public void setLookPosition(GL10 gl,MoveMarble marble_move){
        point.setX(marble_move.getPos().getX()-marble_move.getDirection().getX()*6);
        if(marble_move.getDirection().getY()<=0){
            i=0;
            point.setY(marble_move.getPos().getY()-marble_move.getDirection().getY()*6);
        }
        else{
            point.setY(marble_move.getPos().getY()-i);
            if(i<6*marble_move.getDirection().getY())
                i+=marble_move.getDistance()*marble_move.getDirection().getY();
        }
        point.setZ(marble_move.getPos().getZ()-marble_move.getDirection().getZ()*6);
        Vector dir=Vector.Minus(marble_move.getPos(),point);
        dir.Normalize();
        GLU.gluLookAt(gl,
                point.getX(),point.getY(),point.getZ(),//eye point
                point.getX()+dir.getX()*100,//centre of view
                point.getY()+dir.getY()*100,
                point.getZ()+dir.getZ()*100,0,1,0
                /*
                marble_move.getUp().getX(),//up
                marble_move.getUp().getY(),
                marble_move.getUp().getZ()*/
        );
    }
}